FUNCTION MODULE ZSTB_COUNT_NUMBER_FIELDS
FUNCTION GROUP  ZSTB_FUNCTION_GROUP
DESCRIPTION     count number fields
PROCESSING TYPE : normal function module

EXPORT
PARAMETER   |TYPE_SPEC|ASSOCIATED_TYPE|PASS_VALUE|DESCRIPTION            
------------|---------|---------------|----------|-----------------------
NUMBERFIELDS|TYPE     |INT4           |NO        |number of fields in row

TABLES
PARAMETER     |TYPE_SPEC|ASSOCIATED_TYPE|OPTIONAL|DESCRIPTION         
--------------|---------|---------------|--------|--------------------
TABLE_TO_COUNT|         |               |NO      |table to count field

SOURCE CODE
...........
function zstb_count_number_fields.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXPORTING
*"     REFERENCE(NUMBERFIELDS) TYPE  INT4
*"  TABLES
*"      TABLE_TO_COUNT
*"----------------------------------------------------------------------

data: go_struct type ref to cl_abap_structdescr,
  gt_comp type abap_component_tab.
field-symbols: <datarow> type any.

read table table_to_count assigning <datarow> index 1.
if <datarow> is assigned.
  go_struct ?= cl_abap_typedescr=>describe_by_data( <datarow> ).
  gt_comp = go_struct->get_components( ).
  describe table gt_comp lines numberfields.
endif.

endfunction.